package org.nestor.demo.client;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.nestor.demo.protobuf.RPCDateRequest;
import org.nestor.demo.protobuf.RPCDateResponse;
import org.nestor.demo.protobuf.RPCDateServiceGrpc;

/**
 * grpc客户端
 *
 * @author : Nestor.Bian
 * @version : V 1.0
 * @date : 2025/3/4
 */
public class GRPCClient {
    private static final String host = "localhost";
    private static final int serverPort = 9999;
    public static void main(String[] args) {
        final ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(host, serverPort).usePlaintext().build();

        try {
            final RPCDateServiceGrpc.RPCDateServiceBlockingStub stub = RPCDateServiceGrpc.newBlockingStub(managedChannel);
            final RPCDateResponse response = stub.getDate(RPCDateRequest.newBuilder().setUserName("nestor").build());
            System.out.println("response: " + response.getServerDate());
        } finally {
            managedChannel.shutdown();
        }
    }
}